﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ECRMS.WinForm.WinService;

namespace ECRMS.WinForm.BaseClass.Common
{
    public class IndexOfEvaluate
    {
        public List<CtIndexGroup> IndexGroups;
        public List<CtIndexProcess> OperatorRowIndexs;

        //得到某公司的所有指标组
        public FuncResult GetIndexGroups(Guid corpId,int userTypeId)
        {
            using (var ser = new ECRServiceClient())
            {
                CtServiceResultOfArrayOfCtIndexGroupOUJwPUXg result = ser.CtGetIndexGroups(corpId, userTypeId);
                if (result.Status == 1)
                {
                    this.IndexGroups = result.Data;
                }
                return new FuncResult
                {
                    Status = result.Status,
                    Message = result.Message
                };
            }
        }
        //得到属于某个员工的指标
        public FuncResult GetIndexs(Guid groupId, Guid employeeId,int userType)
        {
            using (var ser = new ECRServiceClient())
            {
                CtServiceResultOfArrayOfCtIndexProcessOUJwPUXg result = ser.CtGetIndexsByGroupIdAndEmployeeId(groupId, employeeId,userType);
                if (result.Status == 1)
                {
                    this.OperatorRowIndexs = result.Data;
                    RefreshIndexs();
                }
                return new FuncResult
                {
                    Status = result.Status,
                    Message = result.Message
                };
            }
        }

        public void RefreshIndexs()
        {
            this.OperatorRowIndexs = (from a in this.OperatorRowIndexs
                                     orderby a.Name1, a.Name2, a.Name3, a.Name4, a.Name5, a.Name6, a.Name7, a.Name8, a.Name9
                                     select a).ToList();
        }
        //修改某个员工的指标测试
        public FuncResult UpdateIndexs()
        {
            using (var ser = new ECRServiceClient())
            {
                CtServiceResult result = ser.CtUpdateIndexProcess(OperatorRowIndexs);
               
                return new FuncResult
                {
                    Status = result.Status,
                    Message = result.Message
                };
            }
        }

        public int GetGroupMaxLevel()
        {
            int result=0;
            foreach (CtIndexProcess item in OperatorRowIndexs)
            {
                if(item.Level>0)
                {
                    result = item.Level; 
                }
            }
            return result;
        }


        //提交测试
        public FuncResult<decimal> EvaluateIndexGroup(Guid corpId)
        {
            using (var ser = new ECRServiceClient())
            {
                CtServiceResultOfdecimal result = ser.CtEvaluateIndexGroup(OperatorRowIndexs, corpId);

                return new FuncResult<decimal>
                {
                    Status = result.Status,
                    Message = result.Message,
                    Data=result.Data
                };
            }
        }

    }
}
